package com.csgc.camera.widget.dialog

import android.content.Context
import android.graphics.Paint
import android.view.Gravity
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.StyleRes
import androidx.core.content.ContextCompat

import com.csgc.camera.util.ViewUtils
import com.csgc.camera.util.clickWithTrigger
import com.csgc.camera.widget.dialog.base.AnimAction
import com.csgc.camera.widget.dialog.base.BaseDialog
import com.cysd.spsyxj.R

import com.drake.spannable.addSpan
import com.drake.spannable.span.ColorSpan
import com.hjq.shape.layout.ShapeLinearLayout
import com.hjq.shape.layout.ShapeRelativeLayout
import com.hjq.shape.view.ShapeTextView

class BuyVipDialog  constructor(context: Context, @StyleRes themeResId: Int = R.style.BaseDialogTheme):
    BaseDialog(context,themeResId) {
    private val buyButton: ShapeTextView? by lazy { findViewById(R.id.tv_buy_vip) }

    private val layoutPayAli: ShapeRelativeLayout? by lazy { findViewById(R.id.layout_ali_pay)  }
    private val aliCheck: ImageView? by lazy { findViewById(R.id.iv_ali_checked)  }

    private val btnClose : ImageView? by lazy { findViewById(R.id.iv_close)  }
    private val layoutPayWx: ShapeRelativeLayout? by lazy { findViewById(R.id.layout_wx_pay)  }
    private val wxCheck: ImageView? by lazy { findViewById(R.id.iv_wx_checked)  }

    //0微信 1支付宝
    private var payType = 0
    var listener:OnItemListener?=null

        init {
            setWidth(ViewUtils.getScreenWidth(context) - ViewUtils.dp2px(30f))
            setContentView(R.layout.dialog_buy_vip_dialog)
            setWindowAnimations(AnimAction.ANIM_IOS)
            setGravity(Gravity.CENTER)
            setCancelable(false)


            btnClose?.clickWithTrigger {
                listener?.onGiveUp()
            }

            buyButton?.clickWithTrigger {
                listener?.onBuyVip(payType)
            }


            layoutPayAli?.clickWithTrigger {
                payType = 1
                aliCheck?.visibility = View.VISIBLE
                wxCheck?.visibility = View.INVISIBLE
            }

            layoutPayWx?.clickWithTrigger {
                payType = 0
                aliCheck?.visibility = View.INVISIBLE
                wxCheck?.visibility = View.VISIBLE
            }

        }


    fun setPrice(salePrice:String,origin:String){


       val text = "立即开通".addSpan("(¥$salePrice)",listOf(ColorSpan(ContextCompat.getColor(context, R.color.color_FE2121))))
        buyButton?.text = text
    }

    interface OnItemListener{
        fun onGiveUp()
        fun onBuyVip(payType:Int)
    }
}